﻿<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="/stylesheets/style.css">
  <link rel="stylesheet" href="/layui/css/layui.css">
  <title>Document</title>
  <style>
  html{
      width: 100%;
      height: 100%;
      background: url("/images/school.jpg") no-repeat;
      background-size:100% 100%;
  }
  #container{
      background-color:cornflowerblue;
      opacity:0.8;
  }
  </style>
</head>
<body>
    <div id="back">
        <div id="container">
        <div id="title">
            <h1>武汉科技大学</h1>
        </div>
        <div id="login">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="password" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" class="layui-btn" onclick="login()" value="登录">
                    </div>
                </div>
            </form>
        </div>
    </div>
    </div>
    <script src="/layui/layui.js"></script>
    <script src="/jquery.min.js"></script>
    <script src="/jquery.cookie.js"></script>
    <script>
        layui.use('form', function () {
            var form = layui.form;
        });
        function login() {
            var data = {
                id: $("#username").val(),
                password: $("#password").val()
            }
            $.ajax({
                url: "http://localhost:3000/login/userLogin",
                type: 'post',
                data: data,
                dataType: 'json',
                success: function (result) {
                    if (result.code == 1) {
                        $.cookie('id',data.id);
                      //  alert("登录成功");
                        location.href = 'http://localhost:3000/users';
                    } else {
                        alert(result.code);
                    }
                },
                error: function (msg) {
                    layui.layer.msg("账号或密码错误");
                }
            })
        }
    </script>
</body>
</html>